package com.ahq.main;

import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import com.dalonedrau.vectors.Vector3;
import com.dalonedrau.jogl.engine.Action;
import com.dalonedrau.jogl.engine.Animation;
import com.dalonedrau.jogl.engine.GameApplet;
import com.dalonedrau.jogl.engine.GlobalConsts;
import com.dalonedrau.jogl.engine.Interactive;
import com.dalonedrau.jogl.engine.Render;
import com.dalonedrau.jogl.opengl.View;
import com.dalonedrau.jogl.opengl.animation.AnimationSequenceObjectFactory;
import com.dalonedrau.jogl.opengl.sprite.BasicQuadSpriteObject;
import com.dalonedrau.jogl.opengl.sprite.BasicSpriteObject;
import com.dalonedrau.jogl.opengl.sprite.BasicTriangleSpriteObject;
import com.dalonedrau.jogl.opengl.sprite.GroupOfImages;
import com.dalonedrau.jogl.opengl.sprite.SpriteBase;
import com.dalonedrau.jogl.opengl.sprite.SpriteImageObject;
import com.dalonedrau.jogl.opengl.sprite.SpriteImageObjectFactory;
import com.dalonedrau.jogl.opengl.ui.Button;
import com.dalonedrau.jogl.opengl.ui.Label;
import com.dalonedrau.jogl.opengl.ui.TextField;
import com.dalonedrau.jogl.opengl.ui.menu.MenuGroup;
import com.dalonedrau.jogl.opengl.ui.menu.MenuItem;
import com.dalonedrau.jogl.opengl.ui.menu.VerticalMenu;
import com.dalonedrau.jogl.util.UtilityMethods;
import com.dalonedrau.pool.PooledStringBuilder;
import com.dalonedrau.pool.StringBuilderPool;
import com.dragonwarriors.player.DWCharCreationScreen;
import com.dragonwarriors.player.DWCharacter;
import com.dragonwarriors.player.DWConsts;
import com.dragonwarriors.player.DWPlayer;
import com.rpg.base.interactive.flyweight.BaseInteractiveObject;
import com.rpg.base.interactive.flyweight.InteractiveObject;
import com.rpg.dragonquest.player.DQCharacter;
import com.rpg.dragonquest.player.DQPCViewer;

/**
 * The title screen view.
 * @author Donald
 */
public final class DWCharCreatorView implements View {
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void handleKeyEvent(final KeyEvent e) {
		switch (e.getKeyCode()) {
		case KeyEvent.VK_ESCAPE:
			System.out.println("esc");
			AHQApplet.getInstance().exit();
			break;
		default:
			DWCharCreationScreen.getInstance().handleKeyEvent(e);
			break;
		}
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void handleMouseOver(final float x, final float y) {
		DWCharCreationScreen.getInstance().handleMouseOver(x, y);
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void handleMousePress(final MouseEvent e, final float x,
			final float y) {
		DWCharCreationScreen.getInstance().handleMouseClick(x, y);
	}
	/** flag indicating the view has been initialized. */
	private boolean runInit = false;
	/**
	 * Initializes the {@link View}.
	 * @throws Exception if an error occurs
	 */
	private void init() throws Exception {
		Point pt = UtilityMethods.getInstance().centerComponentInFrame(
				DWCharCreationScreen.getInstance());
		DWCharCreationScreen.getInstance().setPosition(pt.x, pt.y, 0.0f);
		DWCharCreationScreen.getInstance().setVisible(true);
		runInit = true;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void prepareForRendering() throws Exception {
		if (!runInit) {
			try {
				init();
			} catch (Exception ex) {
				AHQApplet.getInstance().fatalError(ex);
			}
		}
		DWCharCreationScreen.getInstance().prepareForRendering();
	}
}
